package com.mixsmart.commonweb.bean.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

import com.mixsmart.commonweb.IWebConstant;
import com.mixsmart.commonweb.bean.IPKStringBean;
import com.mixsmart.utils.ArrayUtils;
import com.mixsmart.utils.StringUtils;

/**
 * 角色,资源关联实体
 * @author lmq
 * @version 1.0
 * @since 1.0
 * <br />
 * 2016年7月3日
 */
@Entity
@Table(name="t_c_role_url_res")
public class TCRoleUrlRes implements IPKStringBean {

	/**
	 * 
	 */
	private static final long serialVersionUID = 6114897412498903343L;

	private String id;
	
	private String roleId;
	
	private String urlResId;
	
	private String opAuths;
	
	/**
	 * 临时变量
	 */
	private String[] opAuthArray;

	public TCRoleUrlRes() {
		
	}

	public TCRoleUrlRes(String roleId, String urlResId) {
		this.roleId = roleId;
		this.urlResId = urlResId;
	}

	public TCRoleUrlRes(String roleId, String urlResId, String opAuths) {
		this.roleId = roleId;
		this.urlResId = urlResId;
		this.opAuths = opAuths;
	}

	@Id
	@Column(name="id", length=50)
	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	@Column(name="role_id",length=50, nullable=false)
	public String getRoleId() {
		return roleId;
	}

	public void setRoleId(String roleId) {
		this.roleId = roleId;
	}

	@Column(name="url_res_id",length=50, nullable=false)
	public String getUrlResId() {
		return urlResId;
	}

	public void setUrlResId(String urlResId) {
		this.urlResId = urlResId;
	}

	@Column(name="op_auths", length=500)
	public String getOpAuths() {
		return opAuths;
	}

	public void setOpAuths(String opAuths) {
		this.opAuths = opAuths;
	}

	/**
	 * 判断opAuths中是否包含指定的字符串
	 * @param opFlagId
	 * @return
	 */
	@Transient
	public boolean isContains(String opFlagId) {
		boolean is = false;
		if(StringUtils.isNotEmpty(opFlagId)) {
			is = ArrayUtils.isArrayContains(getOpAuthArray(), opFlagId);
		}
		return is;
	}

	@Transient
	public String[] getOpAuthArray() {
		if(StringUtils.isNotEmpty(this.opAuths) && ArrayUtils.isEmpty(this.opAuthArray)) {
			opAuthArray = this.opAuths.split(IWebConstant.MULTI_VALUE_SPLIT);
		}
		return opAuthArray;
	}
}
